/**
 * 
 */
package com.unitspirit.sample;

import org.apache.catalina.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;

/**
 * @author wupf
 *
 */
public class JpfSession {
	private static final Logger LOGGER = LoggerFactory.getLogger(JpfSession.class);

	ThreadLocal<Long> startTime = new ThreadLocal<>();

	public static void main(String[] args) {
		try {
			String str = "{\"attributeNames\":[],\"creationTime\":1585187502740,\"id\":\"06748A23377D69373E0BB84444B59228\",\"lastAccessedTime\":1585187505400,\"maxInactiveInterval\":1800,\"new\":false,\"servletContext\":{\"attributeNames\":[\"javax.servlet.context.tempdir\",\"org.apache.catalina.resources\",\"org.springframework.web.context.WebApplicationContext.ROOT\",\"org.springframework.web.context.support.ServletContextScope\",\"org.apache.tomcat.InstanceManager\",\"org.apache.catalina.jsp_classpath\",\"javax.websocket.server.ServerContainer\",\"org.apache.tomcat.JarScanner\",\"org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet\"],\"contextPath\":\"\",\"defaultSessionTrackingModes\":[\"COOKIE\",\"URL\"],\"effectiveMajorVersion\":3,\"effectiveMinorVersion\":0,\"effectiveSessionTrackingModes\":[\"COOKIE\",\"URL\"],\"filterRegistrations\":{\"requestContextFilter\":{\"className\":\"org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter\",\"initParameters\":{},\"name\":\"requestContextFilter\",\"servletNameMappings\":[],\"urlPatternMappings\":[\"/*\"]},\"Tomcat WebSocket (JSR356) Filter\":{\"className\":\"org.apache.tomcat.websocket.server.WsFilter\",\"initParameters\":{},\"name\":\"Tomcat WebSocket (JSR356) Filter\",\"servletNameMappings\":[],\"urlPatternMappings\":[\"/*\"]},\"httpPutFormContentFilter\":{\"className\":\"org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter\",\"initParameters\":{},\"name\":\"httpPutFormContentFilter\",\"servletNameMappings\":[],\"urlPatternMappings\":[\"/*\"]},\"hiddenHttpMethodFilter\":{\"className\":\"org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter\",\"initParameters\":{},\"name\":\"hiddenHttpMethodFilter\",\"servletNameMappings\":[],\"urlPatternMappings\":[\"/*\"]},\"characterEncodingFilter\":{\"className\":\"org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter\",\"initParameters\":{},\"name\":\"characterEncodingFilter\",\"servletNameMappings\":[],\"urlPatternMappings\":[\"/*\"]},\"webStatFilter\":{\"className\":\"com.alibaba.druid.support.http.WebStatFilter\",\"initParameters\":{\"exclusions\":\"*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*\"},\"name\":\"webStatFilter\",\"servletNameMappings\":[],\"urlPatternMappings\":[\"/*\"]}},\"initParameterNames\":[],\"majorVersion\":3,\"minorVersion\":1,\"serverInfo\":\"Apache Tomcat/8.5.29\",\"servletContextName\":\"application\",\"servletNames\":[],\"servletRegistrations\":{\"default\":{\"className\":\"org.apache.catalina.servlets.DefaultServlet\",\"initParameters\":{\"listings\":\"false\",\"debug\":\"0\"},\"mappings\":[],\"name\":\"default\"},\"dispatcherServlet\":{\"className\":\"org.springframework.web.servlet.DispatcherServlet\",\"initParameters\":{},\"mappings\":[\"/\"],\"name\":\"dispatcherServlet\"},\"statViewServlet\":{\"className\":\"com.alibaba.druid.support.http.StatViewServlet\",\"initParameters\":{},\"mappings\":[\"/druid/*\"],\"name\":\"statViewServlet\"}},\"servlets\":[],\"sessionCookieConfig\":{\"httpOnly\":false,\"maxAge\":-1,\"secure\":false},\"sessionTimeout\":30,\"virtualServerName\":\"Tomcat/localhost\"},\"sessionContext\":{\"ids\":[]},\"valueNames\":[]}";

			Session cSession = JSON.parseObject(str, Session.class);
			System.out.println(cSession.getCreationTime());
		} catch (Exception e) {
			// TODO: handle exception\
			e.printStackTrace();
		}
	}

	private void doAfterReturning2(Object ret) throws Throwable {
		LOGGER.info("WebLogAspect.doAfterReturning : ");
		// 处理完请求，返回内容
		LOGGER.info("RESPONSE : " + ret);

		LOGGER.info("SPEND TIME : " + (System.currentTimeMillis() - startTime.get()));
		startTime.remove();// 用完之后记得清除，不然可能导致内存泄露;
	}
}
